<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateWxCard extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //卡券基础信息表
        Schema::create('wx_card_bases', function (Blueprint $table) {
            $table->increments('card_base_id')->comment('卡券主键唯一ID');
            $table->string('card_id', 200)->default('')->comment('卡券ID');
            $table->string('card_type', 50)->default('')->comment('卡券类型');
            $table->string('card_key', 50)->default('')->comment('卡券标识');
            $table->string('code_type', 50)->default('')->comment('码型');
            $table->string('brand_name', 50)->default('')->comment('商户名字');
            $table->string('title', 100)->default('')->comment('卡券名');
            $table->string('logo_url', 150)->default('')->comment('卡券的商户logo，建议像素为300*300');
            $table->string('color', 30)->default('')->comment('券颜色');
            $table->string('notice', 60)->default('')->comment('卡券使用提醒');
            $table->text('description')->comment('卡券使用说明');
            $table->text('date_info')->comment('使用日期，有效期的信息');
            $table->text('sku')->comment('商品信息');
            $table->unsignedTinyInteger('use_custom_code')->default(0)->comment('是否自定义Code码');
            $table->string('get_custom_code_mode', 30)->default('')->comment('填入 GET_CUSTOM_CODE_MODE_DEPOSIT 表示该卡券为预存code模式卡券');
            $table->unsignedTinyInteger('bind_openid')->default(0)->comment('是否指定用户领取');
            $table->string('service_phone', 50)->default('')->comment('客服电话');
            $table->unsignedTinyInteger('use_all_locations')->default(1)->comment('设置本卡券支持全部门店，与location_id_list互斥');
            $table->text('location_id_list')->nullable()->comment('门店位置poiid');
            $table->text('center_info')->nullable()->comment('卡券顶部居中的按钮信息');
            $table->text('custom_info')->nullable()->comment('自定义跳转信息');
            $table->text('promotion_info')->nullable()->comment('营销场景入口信息');
            $table->unsignedInteger('get_limit')->default(0)->comment('每人可领券的数量限制,不填写默认为50');
            $table->unsignedInteger('use_limit')->default(0)->comment('每人可核销的数量限制,不填写默认为50');
            $table->unsignedTinyInteger('can_share')->default(0)->comment('卡券领取页面是否可分享');
            $table->unsignedTinyInteger('can_give_friend')->default(0)->comment('卡券是否可转赠');
            $table->unsignedTinyInteger('audit_status')->default(0)->comment('审核状态');
            $table->string('audit_result', 200)->default('')->comment('审核结果');
            $table->softDeletes();
            $table->timestamps();
            $table->index(['card_type','deleted_at'], 'index1');
            $table->index(['card_key','card_type','deleted_at'], 'index2');
        });
        //卡券高级信息表
        Schema::create('wx_card_advances', function (Blueprint $table) {
            $table->increments('id')->comment('自增序号');
            $table->unsignedInteger('card_base_id')->default(0)->comment('卡券主键唯一ID');
            $table->text('use_condition')->nullable()->comment('使用门槛');
            $table->text('abstract')->nullable()->comment('封面摘要结构体名称');
            $table->text('text_image_list')->nullable()->comment('图文列表');
            $table->text('time_limit')->nullable()->comment('使用时段限制');
            $table->text('business_service')->nullable()->comment('商家服务类型');
            $table->unsignedTinyInteger('share_friends')->default(0)->comment('是否支持分享给朋友使用');
            $table->softDeletes();
            $table->timestamps();
            $table->index(['card_base_id','deleted_at'], 'index1');
        });
        //会员卡-领取表
        Schema::create('wx_card_receives', function (Blueprint $table) {
            $table->increments('id')->comment('自增序号');
            $table->string('card_type', 50)->default('')->comment('卡券类型');
            $table->string('card_id', 200)->default('')->comment('微信卡券ID');
            $table->string('user_openid', 100)->default('')->comment('领券用户openid');
            $table->string('user_card_code', 200)->default('')->comment('code序列号');
            $table->unsignedTinyInteger('is_give_by_friend')->default(0)->comment('是否为转赠领取');
            $table->string('friend_user_name', 100)->default('')->comment('发起转赠用户的openid');
            $table->string('old_user_card_code', 200)->default('')->comment('转赠前的code');
            $table->string('outer_str', 50)->default('')->comment('领取场景值，用于领取渠道数据统计');
            $table->unsignedTinyInteger('is_restore_member_card')->default(0)->comment('用户删除会员卡后可重新找回');
            $table->timestamp('receive_time')->nullable()->comment('领取时间');
            $table->charset = 'utf8';
            $table->collation = 'utf8_unicode_ci';
            $table->softDeletes();
            $table->timestamps();
            $table->index(['card_id','deleted_at'], 'index1');
            $table->index(['user_card_code','card_id','deleted_at'], 'index2');
        });
        //会员卡-转赠表
        Schema::create('wx_card_transfers', function (Blueprint $table) {
            $table->increments('id')->comment('自增序号');
            $table->string('card_id', 200)->default('')->comment('微信卡券ID');
            $table->string('user_openid', 100)->default('')->comment('领券用户openid');
            $table->string('user_card_code', 200)->default('')->comment('code序列号');
            $table->string('friend_user_openid', 100)->default('')->comment('接收卡券用户的openid');
            $table->unsignedTinyInteger('is_return_back')->default(0)->comment('是否转赠退回');
            $table->unsignedTinyInteger('is_chat_room')->default(0)->comment('是否为群转赠');
            $table->charset = 'utf8';
            $table->collation = 'utf8_unicode_ci';
            $table->softDeletes();
            $table->timestamps();
            $table->index(['card_id','deleted_at'], 'index1');
            $table->index(['user_card_code','card_id','deleted_at'], 'index2');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('wx_card_bases');
        Schema::dropIfExists('wx_card_advances');
        Schema::dropIfExists('wx_card_receives');
        Schema::dropIfExists('wx_card_transfers');
    }
}
